import { Injectable } from '@angular/core';
import { HttpService } from './http.service';
import { API_URL } from '../const/base.const';

@Injectable({
  providedIn: 'root',
})
export class ScenarioService {
  constructor(private $http: HttpService) {}

  //查询所有的Scenarios
  getScenarios(searchKey?: string) {
    let url = API_URL.SCENARIO;
    if (searchKey) {
      url += `?searchKey=${searchKey}`;
    }
    return this.$http.get(url);
  }

  queryBySearchKey(key: string) {
    return this.$http.get(`${API_URL.SCENARIO}/search/${key}`);
  }

  // 根据分页查询scenario数据
  queryAllScenariosByPage(page: number, pageSize: number) {
    return this.$http.post(`${API_URL.SCENARIO}/All`, { page, pageSize });
  }

  getScenarioById(id: number) {
    return this.$http.get(`${API_URL.SCENARIO}/${id}`);
  }

  //保存数据
  postScenario(data: any) {
    return this.$http.post(API_URL.SCENARIO, data);
  }

  updateScenario(id: number, data: any) {
    return this.$http.patch(`${API_URL.SCENARIO}/${id}`, data);
  }

  deleteScenario(fid: number, sid: number) {
    return this.$http.delete(`${API_URL.SCENARIO}/?fid=${fid}&sid=${sid}`);
  }

  copyScenario(id: number) {
    return this.$http.get(`${API_URL.SCENARIO}/copy/${id}`);
  }
}
